<?php

namespace app\vv;

use addons\shopro\library\traits\model\order\OrderOperSendGet;
use addons\shopro\listener\commission\CommissionHook;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
use think\Db;

class ExecListenerOrderPayedAfter extends Command
{
    use OrderOperSendGet;

    protected function configure()
    {
        $this->setName('exec_listener_order_payed_after')->addArgument('order_id', Argument::REQUIRED);
    }

    protected function execute(Input $input, Output $output)
    {
        $order_id = $input->getArgument('order_id');
        $order    = Db::table('fa_shopro_order')->where('id', $order_id)->find();
        if (!$order) {
            $output->write('订单id错误');
            return;
        }
        if ($order['status'] != 1) {
            $output->write('订单状态错误');
            return;
        }
        # 修改发货状态->已发货
        Db::table('fa_shopro_order_item')->where('order_id', $order_id)->update(['dispatch_status' => 1]);
        # 执行分销
        $params   = ['order' => $order];
        $listener = new CommissionHook();
        $listener->orderPayedAfter($params);
        $output->write('ok');
    }
}